package com.example.nuc_ms_beta.ui.viewconstruction.newsfragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.nuc_ms_beta.R;
import com.example.nuc_ms_beta.ui.viewcomponent.indviewpager.ViewPagerIndicator;
import com.example.nuc_ms_beta.ui.viewcomponent.indviewpager.myViewPager;
import com.example.nuc_ms_beta.ui.viewconstruction.moderfragment.CompeteActivityFragment;
import com.example.nuc_ms_beta.ui.viewconstruction.moderfragment.GrowServiceFragment;
import com.example.nuc_ms_beta.ui.viewconstruction.moderfragment.HonorNucFragment;
import com.example.nuc_ms_beta.ui.viewconstruction.moderfragment.HumanLectureFragment;
import com.example.nuc_ms_beta.ui.viewconstruction.moderfragment.LifeCreateFragment;
import com.example.nuc_ms_beta.ui.viewconstruction.moderfragment.NewestFragment;
import com.example.nuc_ms_beta.ui.viewconstruction.moderfragment.NucInNoticeFragment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * Created by 张博川 on 2016/9/2.
 */
public class LifeNewsFragment extends Fragment {
    private Context context;
    private View view;
    private LayoutInflater inflater;
    private ViewPagerIndicator lifelayout_viewpagerIndicator;
    private myViewPager lifelayout_viewpager;
    private List<String> titles = Arrays.asList("推荐", "头条", "视屏", "娱乐", "搞笑", "军事", "图片");
    private List<Fragment> fragments = new ArrayList<>();
    private FragmentPagerAdapter adapter;

    public LifeNewsFragment(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        initView(container);
        return view;
    }

    private void initView(ViewGroup container) {
        this.view = inflater.inflate(R.layout.lifenewslayout, container, false);
        lifelayout_viewpager = (myViewPager) view.findViewById(R.id.lifelayout_viewpager);
        lifelayout_viewpagerIndicator = (ViewPagerIndicator) view.findViewById(R.id.lifelayout_viewpagerIndicator);
        lifelayout_viewpagerIndicator.setTabItemTitle(titles);
        ChildFragmentManager();
        adapter = new FragmentPagerAdapter(getFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return titles.size();
            }
        };
        lifelayout_viewpager.setAdapter(adapter);
        lifelayout_viewpagerIndicator.setViewpager(lifelayout_viewpager, 0);
        //viewpager事件监听机制
        lifelayout_viewpagerIndicator.setPagerListener(new ViewPagerIndicator.PagerOnChangeListener() {
            @Override
            public void onPagerScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPagerSelected(int position) {

            }

            @Override
            public void OnPagerScrollStateChanged(int state) {

            }
        });
    }


    private void ChildFragmentManager() {
        NewestFragment newesfragment = NewestFragment.getInstance();
        fragments.add(newesfragment);
        NucInNoticeFragment nucinnoticefragment = NucInNoticeFragment.getInstance();
        fragments.add(nucinnoticefragment);
        CompeteActivityFragment competeactivityfragment = CompeteActivityFragment.getInstance();
        fragments.add(competeactivityfragment);
        HumanLectureFragment humanlecturefragment = HumanLectureFragment.getInstance();
        fragments.add(humanlecturefragment);
        GrowServiceFragment growservicefragment = GrowServiceFragment.getInstance();
        fragments.add(growservicefragment);
        LifeCreateFragment lifecreatefragment = LifeCreateFragment.getInstance();
        fragments.add(lifecreatefragment);
        HonorNucFragment honornucfragment = HonorNucFragment.getInstance();
        fragments.add(honornucfragment);
    }
}
